package com.shi.common;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code;
    private String message;
    private T data;

    public static <T> Result build(Integer code, T data, String message) {
        Result result = new Result<>();
        result.setCode(code);
        result.setData(data);
        result.setMessage(message);
        return result;
    }

    public static <T> Result ok(T data) {
        return build(ResultCodeEnum.SUCCESS.getCode(), data, ResultCodeEnum.SUCCESS.getMessage());
    }

    public static Result ok() {
        return build(ResultCodeEnum.SUCCESS.getCode(), null, ResultCodeEnum.SUCCESS.getMessage());
    }

    public static Result fail(ResultCodeEnum resultCodeEnum) {
        return build(resultCodeEnum.getCode(), null, resultCodeEnum.getMessage());
    }

    public static Result fail(String message) {
        return build(ResultCodeEnum.FAIL.getCode(), null, message);
    }
}

